$(function(){
var start=0;
var end=9;
var page=1;
var parse=10;
function getinformation(){
	var now = this;
	this.geturl = function(){
		$.ajax({
		'url':'./public/json/brand.json',
		'type':'get',
		'dataType':'json',
		'success':function(str){
			now.getNum(str);
			}
		})
	}
	this.getNum = function(str){
		$('.stblock-body').html(' ')
		if(page <= 0){
			page=0;
		}
		now.setNum(str);
	}
	this.setNum = function(str){
		var n = 0;
		for(var i in str){
			n++;
		}		
		var total = n;
		var parseNum = Math.ceil(n/parse);
		var newarr = now.consoleDom(start,end,str);
		for(var i=0; i<newarr.length;i++){
			$('<div class="list-inbox"><ul><li class="pic"><a href="goods.html?id='+ newarr[i].id +'">'+newarr[i].img+'</a></li>'+newarr[i].brand+'</a></li><li><a href="#">'+newarr[i].title+'</a></li><li><a href="#">'+newarr[i].price+'</a></li></ul></div>').appendTo($('.stblock-body'));
		}
	}
	this.consoleDom = function(start,end,str){
		var arr = [];
		var j = 0;
		console.log(start+","+end);
		$.each(str,function(index,event){
			event.str = j;
			j++;

			if(event.str >=start && event.str<=end){
				arr.push(event);
			}	
		})
		return arr;
	}
}
var list = new getinformation();
list.geturl();
var n = end;
$('#prev').click(function() {
			page = $('.now').text();
			page--;
			if (page <=0) {
				page =1;
			}	
			console.log(page);
			start = page * parse -10;
			end -= n;
			if(end <= n){
				end = n;
			}
			$('.now').text(page);
			list.geturl();
	});
$('#next').click(function() {
			page = $('.now').text();
			page ++;
			if(	page > $('.totalpage').text()-1){
				page = $('.totalpage').text();
			}
			start = page * parse -10;
			end += n;
			if(end >= $('.totalpage').text()*n){
				end = $('.totalpage').text()*n;
			}
			$('.now').text(page);
			list.geturl();
		});
})